<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-20 21:41:37
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-11-07 22:37:15
 * @Descripttion: 系统配置
 */

namespace app\api\controller\user\v1_0\bus;



class Index extends \app\api\controller\user\v1_0\Common
{
    protected $noNeedRight = ['test'];
    /**
     * @Author: 哲学家乔布斯 <wuyangii@qq.com>
     * @brief: 
     * @return 
     * @Descripttion: 首页默认接口
     */    
    public function index(){
        $param = request()->param();
        $page = empty(request()->param('page')) ? 1 : request()->param('page');
        $limit = empty(request()->param('limit')) ? 10 : request()->param('limit');
        $where = [];
    
        if(!empty($param['bus_state'])){
            $where['bus_state'] = $param['bus_state'];
        }else{
            $where['bus_state'] = [1,2];
        }
        $user = (new \app\common\model\User())->where(['id' => $this->UserInfo['id']])->find();
        $bus = (new \app\common\model\Bus())->where(['id' => $user['bus_id']])->find();
        if(empty($bus)){
            return self::errorResult("当前用户暂未开启该功能");
        }
        $order = (new \app\common\model\UserOrders())   
                ->page($page)
                ->limit($limit)
                ->field(['id','addtime','bus_state','num','bus_state','bus_smoney'])
                ->append(['bus_state_text','addtime_text','goods'])
                ->hidden(['addtime'])
                ->where(['bus_id' => $user['bus_id']])
                ->where($where)->select();
        return self::successResult("成功",[
            'money' => [
                'bus_smoney' => $bus['money'],
            ],
            'order' => $order,
        ]);
    }

    
    

}
